<script setup lang="ts">
  import { BasicTable, useTable, TableAction } from '@/components/Table';
  import { columns } from './datas/index.data';

  import { getAccessKeyList } from '@/api/system/accesskey';

  const [registerTable, { reload }] = useTable({
    title: 'AccessKey',
    api: getAccessKeyList,
    columns,
    useSearchForm: false,
    bordered: true,
    showIndexColumn: false,
    pagination: true,
    size: 'small',
    actionColumn: {
      width: 180,
      title: '操作',
      dataIndex: 'action',
      fixed: 'right',
    },
  });

  function handleCreate() {
    console.log('handleCreate');
  }

  function handleEdit(record: Recordable) {
    console.log(record);
  }

  function handleSuccess() {
    reload();
  }
</script>

<template>
  <div>
    <BasicTable @register="registerTable">
      <template #toolbar>
        <a-button type="primary" @click="handleCreate"> 创建AccessKey </a-button>
      </template>
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction
            :actions="[
              {
                icon: 'clarity:note-edit-line',
                tooltip: '禁用',
                onClick: handleEdit.bind(null, record),
              },
            ]"
          />
        </template>
      </template>
    </BasicTable>
  </div>
</template>
